import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, OneToMany, JoinColumn } from 'typeorm';
import { BaseEntity } from '../../../base.entity';
import WipBadRegistrationList from './wip-bad-registration-list.entity';

@Entity({ name: 'wip_bad_registration' })
export default class WipBadRegistration extends BaseEntity {
  @Column({
    type: 'varchar',
    length: 50,
    name: 'bad_registration_code',
    unique: true,
    comment: '不良登记编号',
  })
  @ApiProperty()
  badRegistrationCode: string;

  @Column({ type: 'varchar', length: 50, name: 'order_code', comment: '工单编号' })
  @ApiProperty()
  orderCode: string;

  @Column({ type: 'float', name: 'erp_no', nullable: true, comment: '第三方订单编号' })
  @ApiProperty()
  erpNo: string;

  @Column({
    type: 'varchar',
    length: 50,
    name: 'machine_code',
    comment: '设备编号',
    nullable: true,
  })
  @ApiProperty()
  machineCode: string;

  @Column({ type: 'varchar', name: 'material_code', comment: '产品编号', nullable: true })
  @ApiProperty()
  materialCode: string;

  @Column({ type: 'varchar', name: 'material_name', comment: '产品名称', nullable: true })
  @ApiProperty()
  materialName: string;

  @Column({ type: 'varchar', name: 'version', comment: '版本', nullable: true })
  @ApiProperty()
  version: string;

  @Column({
    type: 'varchar',
    nullable: true,
    name: 'custom_code',
    comment: '客户编码',
  })
  @ApiProperty()
  customCode: string;

  @Column({ type: 'varchar', nullable: true, comment: '客户简称', name: 'custom_short' })
  @ApiProperty()
  customShort: string;

  @Column({ type: 'varchar', nullable: true, comment: '客户名称', name: 'custom_name' })
  @ApiProperty()
  customName: string;

  @Column({ type: 'float', name: 'order_num', comment: '工单数', nullable: true })
  @ApiProperty()
  orderNum: number;

  @Column({ type: 'varchar', length: 50, name: 'shift_code', comment: '班组编码', nullable: true })
  @ApiProperty()
  shiftCode: string;

  @Column({ type: 'varchar', length: 50, name: 'shift_name', comment: '班组名称', nullable: true })
  @ApiProperty()
  shiftName: string;

  @Column({
    type: 'datetime',
    nullable: true,
    name: 'scheduled_start_time',
    comment: '计划开工时间',
  })
  @ApiProperty()
  scheduledStartTime: Date;

  @Column({ type: 'datetime', nullable: true, name: 'scheduled_end_time', comment: '计划完工时间' })
  @ApiProperty()
  scheduledEndTime: Date;

  @Column({ type: 'float', nullable: true, name: 'material_length', comment: '产品长' })
  @ApiProperty()
  materialLength: number;

  @Column({ type: 'float', nullable: true, name: 'material_width', comment: '产品宽' })
  @ApiProperty()
  materialWidth: number;

  @Column({ type: 'float', nullable: true, name: 'material_height', comment: '产品高' })
  @ApiProperty()
  materialHeight: number;

  @Column({ type: 'varchar', nullable: true, comment: '备注' })
  @ApiProperty()
  remark: string;

  @OneToMany(() => WipBadRegistrationList, (item) => item.badRegistration)
  @JoinColumn({ name: 'bad_registration_code', referencedColumnName: 'badRegistrationCode' })
  badRegistrationList: WipBadRegistrationList[];
}
